package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Member;
import cn.wolfcode.crm.service.ILevelService;
import cn.wolfcode.crm.service.IMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

// 会员统计
@Controller
@RequestMapping("memberForm")
public class MemberFormController {

    @Autowired
    private IMemberService memberService;
    @Autowired
    private ILevelService levelService;

    @RequestMapping("")
    public String index(Model model) {
        List<Member> members = memberService.listAll();

        // 普通会员
        int memberCout1 = 0;
        // 非普通会员
        int memberCout2 = 0;


        // 男(性别)
        int manGenger = 0;
        // 女(性别)
        int womenGenger = 0;

        // 线上(来源)
        int resource1 = 0;
        // 线下(来源)
        int resource2 = 0;

        // 普通客人(分组)
        int group1 = 0;
        // 熟客(分组)
        int group2 = 0;


        // 等级1
        int level1 = 0;
        // 等级2
        int level2 = 0;
        // 等级3
        int level3 = 0;
        // 等级4
        int level4 = 0;
        // 等级5
        int level5 = 0;
        // 等级6
        int level6 = 0;
        // 等级7
        int level7 = 0;
        // 等级8
        int level8 = 0;

        // 善良(标签)
        int tag1 = 0;
        // 抠门(标签)
        int tag2 = 0;
        // 人品好(标签)
        int tag3 = 0;
        // 有礼貌(标签)
        int tag4 = 0;
        // 傻(标签)
        int tag5 = 0;
        // 有钱(标签)
        int tag6 = 0;


        for (int i = 0; i < members.size(); i++) {

            Member member = members.get(i);

            // 会员分类
            if("普通会员".equals(member.getLevel().getName())){
                memberCout1++;
            }else{
                memberCout2++;
            }

            // 性别分类
            if("先生".equals(member.getGender().getName())){
                manGenger++;
            }else{
                womenGenger++;
            }

            // 来源分类
            if("线上".equals(member.getResource().getName())){
                resource1++;
            }else{
                resource2++;
            }

            // 分组分来
            if("普通客人".equals(member.getMgroup().getName())){
                group1++;
            }else{
                group2++;
            }

            // 等级分类
            if ("普通会员".equals(member.getLevel().getName())) {
                level1++;
            } else if ("中级会员".equals(member.getLevel().getName())) {
                level2++;
            } else if ("高级会员".equals(member.getLevel().getName())) {
                level3++;
            } else if ("VIP会员".equals(member.getLevel().getName())) {
                level4++;
            } else if ("黄金会员".equals(member.getLevel().getName())) {
                level5++;
            } else if ("铂金会员".equals(member.getLevel().getName())) {
                level6++;
            } else if ("至尊会员".equals(member.getLevel().getName())) {
                level7++;
            } else {
                level8++;
            }

            // 标签分类
            if ("善良".equals(member.getTag().getName())) {
                tag1++;
            } else if ("抠门".equals(member.getTag().getName())) {
                tag2++;
            } else if ("人品好".equals(member.getTag().getName())) {
                tag3++;
            } else if ("有礼貌".equals(member.getTag().getName())) {
                tag4++;
            } else if ("傻".equals(member.getTag().getName())) {
                tag5++;
            } else {
                tag6++;
            }

        }

        model.addAttribute("count", members.size());
        model.addAttribute("memberCout1", memberCout1);
        model.addAttribute("memberCout2", memberCout2);
        model.addAttribute("res1", resource1);
        model.addAttribute("res2", resource2);
        model.addAttribute("manGenger", (float)manGenger/members.size());
        model.addAttribute("womenGenger", (float)womenGenger/members.size());
        model.addAttribute("resource1", (float)resource1/members.size());
        model.addAttribute("resource2", (float)resource2/members.size());
        model.addAttribute("group1", (float)group1/members.size());
        model.addAttribute("group2", (float)group2/members.size());

        // 标签
        model.addAttribute("tag1", (float)tag1/members.size());
        model.addAttribute("tag2", (float)tag2/members.size());
        model.addAttribute("tag3", (float)tag3/members.size());
        model.addAttribute("tag4", (float)tag4/members.size());
        model.addAttribute("tag5", (float)tag5/members.size());
        model.addAttribute("tag6", (float)tag6/members.size());


        // 会员分析
        model.addAttribute("level1", (float)level1/members.size());
        model.addAttribute("level2", (float)level2/members.size());
        model.addAttribute("level3", (float)level3/members.size());
        model.addAttribute("level4", (float)level4/members.size());
        model.addAttribute("level5", (float)level5/members.size());
        model.addAttribute("level6", (float)level6/members.size());
        model.addAttribute("level7", (float)level7/members.size());
        model.addAttribute("level8", (float)level8/members.size());

        return "memberForm";
    }

}
